﻿package mortal.game.view.forging.renderer
{
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.forging.data.*;
    import mortal.mvc.core.*;

    public class RefreshPropCellRenderer extends GCellRenderer
    {
        private var _attrName:GTextFiled;
        private var _attrValue:GTextFiled;
        private var _hotValue:GTextFiled;
        private var _starLevel:GTextFiled;
        private var _lockBmp:GBitmap;
        private var _lockSpr:GSprite;
        private var _lockBg:ScaleBitmap;
        private var _isLocked:Boolean;
        private var _propData:RefreshPropVO;
        private var _swfPlayer1:SWFPlayer;

        public function RefreshPropCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._attrName = UIFactory.gTextField("", 10, 0, 55, 20, this);
            this._attrValue = UIFactory.gTextField("", 54, 0, 40, 20, this);
            this._starLevel = UIFactory.gTextField("", 103, 0, 40, 20, this);
            this._hotValue = UIFactory.gTextField("+9999", 124 + 6, 0, 60, 20, this, GlobalStyle.textFormatHuang2);
            this._lockSpr = UICompomentPool.getUICompoment(GSprite);
            this._lockSpr.x = 151 + 26;
            this._lockSpr.y = 5;
            this.addChild(this._lockSpr);
            this._lockSpr.mouseEnabled = true;
            this._lockBmp = UIFactory.gBitmap("", 0, 0, this._lockSpr);
            this._lockSpr.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._lockSpr.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._lockBg = UIFactory.bg(1 + 5, 1, 170, 20, this, ImagesConst.RefreshAttrLockBg);
            this._swfPlayer1 = UICompomentPool.getUICompoment(SWFPlayer);
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            Dispatcher.addEventListener(EventName.ForgingPlayRefreshEffect, this.onShowRefreshEffect);
            Dispatcher.addEventListener(EventName.ForgingPlayReplaceEffect, this.onShowReplaceEffect);
            return;
        }// end function

        private function removeListeners() : void
        {
            Dispatcher.removeEventListener(EventName.ForgingPlayRefreshEffect, this.onShowRefreshEffect);
            Dispatcher.removeEventListener(EventName.ForgingPlayReplaceEffect, this.onShowReplaceEffect);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super._data = param1;
            this._propData = param1 as RefreshPropVO;
            if (this._propData)
            {
                this._attrName.text = this._propData.attrName;
                this._attrValue.text = "+" + this._propData.attrValue;
                this._starLevel.text = Language.getStringByParam(41054, this._propData.attrStar);
                if (this._propData.hotAddValue > 0)
                {
                    this._hotValue.text = "+" + this._propData.hotAddValue;
                    this._hotValue.x = this._starLevel.x + this._starLevel.textWidth + 2;
                }
                else
                {
                    this._hotValue.text = "";
                }
                this._isLocked = this._propData.isLock;
                if (this._propData.isLock)
                {
                    this._lockBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.LockIcon2);
                    this._lockBg.visible = true;
                }
                else
                {
                    this._lockBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.UnLockIcon2);
                    this._lockBg.visible = false;
                }
                this.setColor(this._propData.isLock);
            }
            return;
        }// end function

        private function setColor(param1:Boolean) : void
        {
            if (param1)
            {
                this._attrName.textColor = GlobalStyle.colorHuangUint;
                this._attrValue.textColor = GlobalStyle.colorHuangUint;
                this._starLevel.textColor = GlobalStyle.colorHuangUint;
            }
            else
            {
                this._attrName.textColor = this._propData.color;
                this._attrValue.textColor = this._propData.color;
                this._starLevel.textColor = this._propData.color;
            }
            return;
        }// end function

        public function setLockDisabled() : void
        {
            this._lockSpr.mouseChildren = false;
            this._lockSpr.mouseEnabled = false;
            this._lockSpr.filters = [FilterConst.colorFilter];
            this._lockBmp.filters = [FilterConst.colorFilter];
            return;
        }// end function

        public function hideLock() : void
        {
            this._lockSpr.visible = false;
            return;
        }// end function

        public function changePosition() : void
        {
            this._lockBg.width = 123;
            this._attrName.x = 4;
            this._attrValue.x = 44;
            this._starLevel.x = 87;
            return;
        }// end function

        private function onShowRefreshEffect(event:DataEvent) : void
        {
            if (this.parent && this._propData && !this._propData.isLock && !this._propData.isOwnAttr)
            {
                this._swfPlayer1.move(73, 12);
                this._swfPlayer1.load("RefreshInnerFlowEffect.swf", ModelType.NormalSwf, null);
                this._swfPlayer1.framesPlayerCompleteHandler = this.secondEffectEndHandler;
                this.addChild(this._swfPlayer1);
            }
            return;
        }// end function

        private function onShowReplaceEffect(event:DataEvent) : void
        {
            if (this.parent && this._propData && !this._propData.isLock && this._propData.isOwnAttr)
            {
                this._swfPlayer1.move(74, 12);
                this._swfPlayer1.load("RefreshOutFlowEffect.swf", ModelType.NormalSwf, null);
                this._swfPlayer1.framesPlayerCompleteHandler = this.firstEffectEndHandler;
                this.addChild(this._swfPlayer1);
            }
            return;
        }// end function

        private function firstEffectEndHandler(param1:SWFPlayer) : void
        {
            this._swfPlayer1.stop();
            DisplayUtil.removeMe(this._swfPlayer1);
            return;
        }// end function

        private function secondEffectEndHandler(param1:SWFPlayer) : void
        {
            this._swfPlayer1.stop();
            DisplayUtil.removeMe(this._swfPlayer1);
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        public function get isLocked() : Boolean
        {
            return this._isLocked;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._attrName.dispose(param1);
            this._attrValue.dispose(param1);
            this._starLevel.dispose(param1);
            this._lockBmp.dispose(param1);
            this._lockBg.dispose(param1);
            this._swfPlayer1.dispose(param1);
            this._lockSpr.dispose(param1);
            this._hotValue.dispose();
            this._attrName = null;
            this._attrValue = null;
            this._starLevel = null;
            this._lockBmp = null;
            this._lockBg = null;
            this._swfPlayer1 = null;
            this._propData = null;
            this._lockSpr = null;
            this._hotValue = null;
            this.removeListeners();
            return;
        }// end function

    }
}
